package day07.hashMap_treeMap;

import day07.bean.Moon;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.TreeMap;

/**
 * <>
 * <treeMap 有序，hashMap 无序>
 *    默认按键的升序排序
 *
 * @Author WANG.SONG.
 * @Date 2019/3/1 0001 22:22
 * @see
 */
public class HashMapAndTreeMap {
    /**
     *<升序排序>
     *@param
     *
     *@see Moon
     *@return
     *@Author WANG.SONG.
     */
    public static void treeMap(){

        Map<Moon,String> treeMap = new TreeMap<>();
        treeMap.put(new Moon(1,"c"),"one");
        treeMap.put(new Moon(3,"d"),"one");
        treeMap.put(new Moon(2,"e"),"one");
        treeMap.put(new Moon(4,"f"),"one");
        /**K 存放null都会报NPE异常**/
        //treeMap.put(null,"11");
        treeMap.put(new Moon(5,"f"),null);

        for (Moon integer : treeMap.keySet()) {
            System.out.println("treeMap排序："+integer.getX());
        }
    }


    public static void hashMap(){
        Map<Integer,String> map = new HashMap<>();
        map.put(3,"33");
        map.put(1,"11");
        map.put(2,"22");

        for (Integer integer : map.keySet()) {
            System.out.println("hashMap不排序："+integer);
        }
    }

}
